package com.kompas.bola.application.adapter;

import java.util.List;
import com.kompas.bola.application.R;
import com.kompas.bola.application.model.ContentDetail;
import com.kompas.bola.application.utils.Constants;
import com.kompas.bola.application.utils.ImageLoader;
import com.kompas.bola.application.utils.TimeUtils;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListCommentAdapter extends BaseAdapter  {
	/** =========================================================================== */   
	private Activity activity;
	private List<ContentDetail> data;
	private static LayoutInflater inflater = null;
    public ImageLoader imageLoader;     
	/** =========================================================================== */   
	public ListCommentAdapter(Activity a, List<ContentDetail> d) {
		activity 					= a;
		data 						= d;
		inflater 					= (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader					= new ImageLoader(activity.getApplicationContext());
	}
	/** =========================================================================== */   
	public int getCount() {
		return data.size();
	}
	/** =========================================================================== */   
	public Object getItem(int position) {
		return position;
	}
	/** =========================================================================== */   
	public long getItemId(int position) {
		return position;
	}
	/** =========================================================================== */   
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;		
		
		vi 							= inflater.inflate(R.layout.list_detail_comment, null);	

		ImageView  thumb_image 		= (ImageView) vi.findViewById(R.id.comment_user_image); // user image
		TextView name				= (TextView) vi.findViewById(R.id.comment_username); // user name
		TextView time 				= (TextView) vi.findViewById(R.id.comment_timestamp); // user time stamp
		TextView comment			= (TextView) vi.findViewById(R.id.comment_text); // comment text
        
        ContentDetail bolaDetail	= new ContentDetail();
        bolaDetail					= data.get(position);        

		imageLoader.DisplayImage(bolaDetail.getPROFILE_PICTURE(),thumb_image,Constants.SCALETYPE_FIT_CENTER);	
        name.setText(bolaDetail.getUSER_NAME());
		time.setText(TimeUtils.getTimestampComment(bolaDetail.getPUB_DATE()));
		comment.setText(bolaDetail.getCOMMENT());
		
		return vi;
	}
	/** =========================================================================== */
}
